/* Copyright 2017, 2018, 2019, 2020 Gabriel Czernikier
 *
 * This file is part of Côtehaus.
 * Côtehaus is free software: you can redistribute it and/or modify
 * it under the terms of one of the following:
 * 1. The same dual license as that of Côtehaus itself, of which individual licenses are
 * the MIT License and the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 2. The MIT License.
 * 3. The GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * Côtehaus is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * MIT License and the GNU General Public License for more details.
 * You should have received a copy of the MIT License and the GNU General Public License
 * along with Côtehaus.  If not, see <https://opensource.org/licenses/MIT> and <http://www.gnu.org/licenses/>.
 */
#ifndef __CH_UNRESOLVED_TYPE_H
#define __CH_UNRESOLVED_TYPE_H
#include<stdbool.h>
#include "types.h"
 /* Java 7 grammar's ReferenceType, in specific contexts is taken as unresolved_type_id.
 * unresolved_type_id={RefTyp_group, search_context, set_type_id_method, method_param}, search_context=<package, import, enclosing_context>, 'A is enclosing context of 'B' if there's a "class A { class B {} }". 'A' is always enclosing context of 'A', because "class A { A a; }" has a meaning.
 * After resolve_types executes, unresolved_type_id = {+type_id} to be acquainted by proto_id_item, field_id_item, type_list et. al.  For example [proto_id_item={type_id such that ((unresolved_type_id, set_type_id_method, method_param))==proto_id_item and unresolved_type_id={type_id}}]
 *
 * What is what?
 * search_entry: It makes paths that encode the fully qualified names and provides the means to reach them thru unqualified names and orient the path by adding qualifiers.
 * search_context_item: It drives the search path. search_entry'ies usually cater many paths to quallify a name. search_context_item says which one path shall be taken.
 * unresolved_type: It has the unquallified, partly or unadmitted-if-fully quallified names. It matches a search_entry to start a path and can match many more as quallifiers can be derived from its name.
 */

enum search_context_type_enu {
	IMPORT,
	ENTRY
};

// DEPRECATED as of new context.h API
// Members of search_context_stack: among search_context_items, each one is a context head thereof.
struct search_context_st {
	struct list_head context_head;   //struct search_context_item_st : items conforming this context.
	struct list_head context_head_list;   //struct search_context_st : contexts pushed onto a context stack
};

struct search_context_item_st {
	union {
		struct token_list_st *Import_particles;
		struct search_entry_st *search_entry
	} search_context_item_entry;
	enum search_context_type_enu search_context_type;
	struct list_head search_context;   // A list which this search_context_item is member of.
};

void add_unresolved_type(struct token_list_st *RefTyp_group, struct list_head search_context_item_head, struct type_id_st **type_id_to_resolve);

/* DEPRECATED use search_context_item_new
 * Adds a struct search_context_item_st*. If head is NULL returns a new head. Otherwise returns the same head.
 * Effectively, as a NULL is passed for head, a new search_context gets created.
 * Either Import_particles or search_entry must be NULL, and the other one must be not.*/
void add_search_context_item(struct token_list_st *Import_particles, struct search_entry_st * search_entry);
void search_context_item_new(struct token_list_st *Import_particles, struct search_entry_st * search_entry);
// DEPRECATED
void add_tail_search_context_item(struct token_list_st *Import_particles, struct search_entry_st * search_entry);
// All the following 3 DEPRECATED use context.h API
// For when a recursion is made into a state that requires a context copy.
struct search_context_st *push_search_context_copy();
struct search_context_st *pop_search_context();
struct search_context_st *peek_search_context();

#endif
